﻿using System.ComponentModel;
using System.Globalization;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WPF_1_lib;

namespace WPF_1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            //x:Class="WPF_1.MainWindow" 共同生成类（xmal与cs） MainWindow派生自Window
            //x name  name 非此类必须x：name
            this.Btn_test1.Click += Btn_test1_Click;
        }

        

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Human human =this.FindResource("human") as Human;
            if (human != null)
            {
                MessageBox.Show(human.Name +";" +human.Child.Name);
            }
        }

        private void Btn_test1_Click(object sender, RoutedEventArgs e)
        {
            txt1.Text = "hello,bing";
        }
        private void Btn_test1_Click1(object sender, RoutedEventArgs e)
        {
            txt1.Text = "hello,bing";
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            // 创建 MainSalary 窗体的实例
            MainSalary mainSalaryWindow = new MainSalary();

            // 显示窗体
            mainSalaryWindow.Show();
        }

        private void Btn_X_Click(object sender, RoutedEventArgs e)
        {
            XModeTest xModeTest = new XModeTest();
            xModeTest.Show();
        }
    }

    [TypeConverter(typeof(NameToHuman))]
    public class Human
    {
        public string Name { get; set; }
        public Human Child { get; set; }
    } 

    public class NameToHuman : TypeConverter 
    {
        public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
        {
            string name = value.ToString();
            Human child = new Human();
            child.Name = name;

            return child;
        }
    }
}